package JPetStore.persistence.impl;

import JPetStore.persistence.DBUtil;
import JPetStore.persistence.LogDAO;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class LogDAOImpl implements LogDAO {
    private static final String INSERT = "insert into log ( username, content) values(?,?)";
    private static final String DELETE = "DELETE * FROM log";

    public LogDAOImpl() {
    }

    public void insertLog(String username, String Login) {
        try {
            Connection connection = DBUtil.getConnection();
            PreparedStatement pstm = connection.prepareStatement(INSERT);
            pstm.setString(1, username);
            pstm.setString(2, Login);
            pstm.executeUpdate();
            DBUtil.closePreparedStatement(pstm);
            DBUtil.closeConnection(connection);
        } catch (Exception var5) {
            var5.printStackTrace();
        }

    }

    public void clearLog() {
        try {
            Connection connection = DBUtil.getConnection();
            PreparedStatement pstm = connection.prepareStatement(DELETE);
            DBUtil.closePreparedStatement(pstm);
            DBUtil.closeConnection(connection);
        } catch (Exception var3) {
            var3.printStackTrace();
        }

    }
}
